package zs;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        third();
    }

    public static void third() {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int count=0;
        int i=0;
        while (N!=0){
            count+=helper(N%10,i++);
            N=N/10;
        }
        System.out.println(count);
    }
    private static int helper(int n,int m){
        int base=(n>6?3:(n>5?2:(n>2?1:(n>0?0:4))));
        return base*(int)Math.pow(4,m);
    }

    public static void second() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n <= 0) {
            System.out.println(0);
            return;
        }
        if (n < 2) {
            System.out.println(1);
            return;
        }
        int[] nums = new int[n + 1];
        nums[0] = 1;
        nums[1] = 1;
        for (int i = 2; i <= nums.length; i++) {
            nums[i] = nums[i - 1] + nums[i - 2];
        }
        System.out.println(nums[n]);

    }

    public static void first() {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] strings = str.split(" ");
        int[] kids = new int[strings.length];
        for (int i = 0; i < kids.length; i++) {
            kids[i] = Integer.parseInt(strings[i]);
        }
        str = sc.nextLine();
        strings = str.split(" ");
        int[] candies = new int[strings.length];
        for (int i = 0; i < strings.length; i++) {
            candies[i] = Integer.parseInt(strings[i]);
        }
        Arrays.sort(kids);
        Arrays.sort(candies);
        int j = 0;
        int count = 0;
        for (int kid : kids) {
            for (; j < candies.length; j++) {
                if (candies[j] >= kid) {
                    count++;
                    j++;
                    break;
                }
            }
            if (j == candies.length) break;
        }
        System.out.println(count);

    }
}
